namespace XTengine
{
    public struct ValueFlagPair<T>
    {
        private T _value;
        public bool Flag { get; private set; }

        private T _contraint;

        public ValueFlagPair(T constraint)
            : this()
        {
            this._value = default(T);
            this._contraint = constraint;

            this.CheckFlag();
        }

        internal void CheckFlag()
        {
            T thisConstraint = this._contraint;
            T thisValue = this._value;

            this.Flag = !thisConstraint.Equals(thisValue);
        }

        public void ForceFlag(bool flag)
        {
            this.Flag = flag;
        }

        public T Value
        {
            get { return this._value; }

            set
            {
                this._value = value;

                this.CheckFlag();
            }
        }
    }
}
